package com.qf.smsplatform.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * projectName: sms-platform
 *
 * @author: 黄睿武
 * time: 2021/8/22 23:06
 * description: 创建ES连接对象的配置类
 */

@Configuration
public class RestHighLevelClientConfig {

    @Value("${elasticsearch.host}")
    private String host;
    @Value("${elasticsearch.port}")
    private int port;

    @Bean
    public RestHighLevelClient restHighLevelClient(){

        HttpHost hosts = new HttpHost(host,port);

        RestClientBuilder builder = RestClient.builder(hosts);

        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);

        return restHighLevelClient;
    }






}
